{template 'tpl_header'}
<div class="weui-tab__panel">
    <div class="swiper-container">
        <div class="swiper-wrapper">
            {loop $setting['line_thumbs'] $thumbs}
            <div class="swiper-slide">
                <img src="{php echo tomedia($thumbs)}"/>
            </div>
            {/loop}
        </div>
        <div class="swiper-pagination"></div>
    </div>

    <div class="weui-body__bg_color line-list">
        {if !empty($lines) }
        {loop $lines $line}
        <div class="weui-flex weui-flex__col2" style="position: relative">
            <div class="weui-flex weui-flex__col2">
                <a href="{php echo url('entry', array('m' => 'vj_bontrip','do' => 'line','id' => $line['id'],'op' => 'detail'),true);}"
                   class="weui-flex__item weui-flex__col2__style2">
                    <img src="{php echo tomedia($line['thumb'])}">
                    <div class="weui-flex__col2__style2__title">
                        <span>{$line['name']}</span>
                    </div>
                    <div class="weui-flex__col2__style2__desc">
                        <span>{$line['introduction']}</span>
                    </div>
                    {if !empty($line['tag']) }
                    <div class="weui-flex__col2__style2__place" style="display: inherit;">
                        {php $tags = explode(',',$line['tag']) }
                        {loop $tags $tag}
                        <span class="weui-flex__col2__style2__label">{$tag}</span>
                        {/loop}
                        <div style="clear: both;"></div>
                    </div>
                    {/if}
                    <div class="weui-flex__col2__style2__price">
                        <span>¥{php echo $line['price']}／人起</span>
                    </div>
                </a>
                {if !empty($line['label']) }
                <div class="weui-flex__col2__top_tag">
                    <div class="weui-flex__col2__top_tag_content">
                        <span>&bull;</span><br>
                        <span>{$line['label']}</span>
                    </div>
                    <div class="weui-flex__col2__top_tag_border"></div>
                </div>
                {/if}
            </div>
        </div>
        {/loop}
        {else}
        <div id="list_null" class="weui-loadmore weui-loadmore_line">
            <span class="weui-loadmore__tips">暂无数据</span>
        </div>
        {/if}
    </div>

    <div id="loading" class="weui-loadmore">
        <i class="weui-loading"></i>
        <span class="weui-loadmore__tips">正在加载</span>
    </div>

    <div class="weui-tabbar">
        <a href="{php echo $this->createMobileUrl('list'); }" class="weui-tabbar__item">
            <div class="weui-tabbar__icon">
                <i class="iconfont icon-zhixing"></i>
            </div>
            <p class="weui-tabbar__label">知行</p>
        </a>
        <a href="javascript:;" class="weui-tabbar__item weui-bar__item--on">
            <div class="weui-tabbar__icon">
                <i class="iconfont icon-xianlu"></i>
            </div>
            <p class="weui-tabbar__label">线路</p>
        </a>
        <a href="{php echo $this->createMobileUrl('insurance'); }" class="weui-tabbar__item">
            <div class="weui-tabbar__icon">
                <i class="iconfont icon-baoxianxiaoshou1"></i>
            </div>
            <p class="weui-tabbar__label">保险</p>
        </a>
        <a href="{php echo $this->createMobileUrl('me'); }" class="weui-tabbar__item">
            <div class="weui-tabbar__icon">
                <i class="iconfont icon-account"></i>
            </div>
            <p class="weui-tabbar__label">我</p>
        </a>
    </div>
</div>

{template 'tpl_footer'}
<script src="{MOBILE_RES}js/swiper.min.js"></script>
<script>
    $('#loading').hide();
    var line_page = 2;
    var line_is_next = '{$is_next}';
    $(function () {
        $(".swiper-container").swiper({
            loop: true,
            autoplay: 3000
        });

        $(document).scroll(function () {
            //当滚动条到底部时请求数据
            if ($('body').scrollHeight() - $('body').height() - 3 <= $(window).scrollTop()) {
                if (line_is_next == '1') {
                    //防止重复请求
                    line_is_next = '0';
                    $('#loading').show();
                    var data = {
                        'action': 'line_list',
                        'page': line_page,
                    };
                    $.ajax({
                        url: "{php echo $this->createMobileUrl('ajax')}",
                        type: 'post',
                        data: data,
                        dataType: 'json',
                        success: function (res) {
                            if (res.status == 1) {
                                line_is_next = (res.data.is_next) ? '1' : '0';
                                console.log(res.data.list);
                                $('#loading').hide();
                                line_page++;
                                add_line(res.data.list);
                            } else {
                                $.toast(res.msg, "cancel");
                            }
                        },
                        error: function (res) {
                            $.toast('请求失败，请检测网络或联系客服', "cancel");
                        }
                    });
                }
            }
        });
    });

    function add_line(list) {
        var html = '';
        for (li in list) {
            var url = "{php echo url('entry', array('m' => 'vj_bontrip','do' => 'line','op' => 'detail'),true);}";
            url += "&id=" + list[li].id;
            html += '<div class="weui-flex weui-flex__col2" style="position: relative">\n' +
                '        <div class="weui-flex weui-flex__col2">\n' +
                '            <a href="' + url + '" class="weui-flex__item weui-flex__col2__style2">\n' +
                '                <img src="' + list[li].thumb + '">\n' +
                '                <div class="weui-flex__col2__style2__title">\n' +
                '                    <span>' + list[li].name + '</span>\n' +
                '                </div>\n' +
                '                <div class="weui-flex__col2__style2__desc">\n' +
                '                    <span>' + list[li].introduction + '</span>\n' +
                '                </div>\n';

            if (list[li].tag != null) {
                html += '<div class="weui-flex__col2__style2__place" style="display: inherit;">';
                for (tag in list[li].tag) {
                    html += '<span class="weui-flex__col2__style2__label">' + list[li].tag[tag] + '</span>\n';
                }
                html += '<div style="clear: both;"></div></div>';
            }
            html += '                <div class="weui-flex__col2__style2__price">\n' +
                '                    <span>¥' + list[li].price + '／人起</span>\n' +
                '                </div>\n' +
                '            </a>\n';
            if (list[li].label != '') {
                html += '<div class="weui-flex__col2__top_tag">\n' +
                    '                <div class="weui-flex__col2__top_tag_content">\n' +
                    '                    <span>&bull;</span><br>\n' +
                    '                    <span>' + list[li].label + '</span>\n' +
                    '                </div>\n' +
                    '                <div class="weui-flex__col2__top_tag_border"></div>\n' +
                    '            </div>'
            }
            html += '        </div>\n' +
                '    </div>';
        }
        $('.weui-body__bg_color').append(html);
    }

</script>